//
//  YTMineSetVC.m
//  CllForIOS
//
//  Created by qiyun on 2018/3/19.
//  Copyright © 2018年 aRui. All rights reserved.
//

#import "YTMineSetVC.h"
#import "YTTabBarController.h"
@interface YTMineSetVC ()

@end

@implementation YTMineSetVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setNav];
    self.view.backgroundColor=RGBA(236, 236, 236);
    
    UIButton*loginoutBtn=[[UIButton alloc]initWithFrame:CGRectMake(10, SCREEN_H-AfW(48)-AfW(52), SCREEN_W-20, AfW(48))];
    [loginoutBtn setTitle:@"退出登录" forState:UIControlStateNormal];
    [loginoutBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [loginoutBtn setBackgroundColor:RGBA(234, 49, 47)];
    loginoutBtn.titleLabel.font=KFONT(14);
    [loginoutBtn.layer setCornerRadius:3];
    loginoutBtn.layer.masksToBounds = YES;
    [self.view addSubview:loginoutBtn];
    [loginoutBtn addTarget:self action:@selector(toLoginout) forControlEvents:UIControlEventTouchUpInside];
    
    
}

-(void)setNav{
    self.titleLabel.text=@"设置";
    self.lineView.hidden=YES;
    [self.leftimaBtn setImage:IMAGE(@"Mine_back") forState:UIControlStateNormal];
}
-(void)toLoginout{
    NSLog(@"退出");
    [Tookit showAlert:@"确定要退出登录?" delegate:self buttonTitle:@"确定" otherButtonTitles:@"取消" tag:11111];
}
#pragma mark - alert
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (alertView.tag == 11111 && buttonIndex == 0){
        //调退出接口
        [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        NSMutableDictionary *data = [Tookit getUserCasheInfo];
        NSString*token= [data objectForKey:@"token"];
        
        [SendRequest getinfoDetailWithURL:k_MainUrl(k_User_logout) withDictionary:@{@"token":token} result:^(NSDictionary*result,NSError*error){
            if (result) {
                NSMutableDictionary *data = [Tookit getUserCasheInfo];
                [data setObject:@"" forKey:@"token"];
                [data setObject:@(NO) forKey:@"whiteList2"];
                
                [data setObject:@"" forKey:@"account"];
                [data setObject:@"" forKey:@"mobile"];
                
                [data setObject:@"" forKey:@"password"];
                [data setObject:@"" forKey:@"name"];
                [data setObject:@"" forKey:@"certNo"];
                [data setObject:@"" forKey:@"username"];
                [data setObject:@"" forKey:@"autologinpassword"];
                
                
                [Tookit saveUserCasheInfo:data];
                
                YTTabBarController*vc= [YTTabBarController new];
            
                [self.navigationController pushViewController:vc animated:1];
                self.navigationController.viewControllers=@[vc];
                
            }else{
                
            }
           [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        }];
     
    }
    return;
}
@end
